package java6681.lesson12;

import java.util.ArrayList;

/**
 * @author Junichiro
 * @description
 * @date 2021-05-29 19:28
 **/

public class test {
    public static void main(String[] args) {
        int i = 0;
        int k = 0;
        int sum = 0;
        ArrayList prime = new ArrayList();
        int[] num = new int[40];

        System.out.print("产生的随机数是：");
        for (i = 0; i < num.length; i++) {
            // 数组赋值
            num[i] = (int) (Math.random() * 61);
            System.out.print(num[i] + " ");
        }
        System.out.println();
        for (int j = 0; j < num.length; j++) {
            for (k = 2; k < num[j]; k++) { // 判断能不能被整除
                if ((num[j] % k) == 0) {
                    break;
                }
            }
            if (k == num[j]) // 如果以上都不是,就是k与zhengShu[j]
            {
                sum += num[j];
                prime.add(num[j]); // 把数加到数组中
            }
        }
        System.out.println("素数：");

        for (int q = 0; q < prime.size(); q++) {
            System.out.print(prime.get(q) + " ");
        }
        System.out.print(" = "+sum);
    }
}
